package com.stormrage.edu.serv.edu.impl;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.stormrage.edu.dao.edu.EduLecDao;
import com.stormrage.edu.serv.edu.EduLecServ;
import com.stormrage.entity.edu.EduLec;
import com.stormragetech.core.exception.StormrageTechException;
import com.stormragetech.core.util.StrUtil;

/**
 * @Title: EduLecServImpl.java
 * @Package com.stormrage.edu.serv.edu.impl
 * @Description: 讲师 Service
 * @author www.stormragetech.com
 * @date 2016年4月16日
 * @version V1.0
 */
@Service
public class EduLecServImpl implements EduLecServ {

	private static final Logger logger = LoggerFactory.getLogger(EduLecServImpl.class);

	@Autowired
	private EduLecDao eduLecDao;

	@Override
	public EduLec queryById(Integer id) throws StormrageTechException {

		logger.debug(" 【 Serv 】-【 EduLecServ 】-【 QueryById 】-【 STARTED 】");

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", id);

		EduLec entity = eduLecDao.queryById(map);

		logger.debug(" 【 Serv 】-【 EduLecServ 】-【 QueryById 】-【 COMPLETED 】");
		return entity;

	}

	@Override
	public List<EduLec> queryList() throws StormrageTechException {

		logger.debug(" 【 Serv 】-【 EduLecServ 】-【 QueryList 】-【 STARTED 】");

		List<EduLec> array = eduLecDao.queryList();

		logger.debug(" 【 Serv 】-【 EduLecServ 】-【 QueryList 】-【 COMPLETED 】");
		return array;

	}

	@Override
	public List<EduLec> queryListForIndex() throws StormrageTechException {

		logger.debug(" 【 Serv 】-【 EduLecServ 】-【 QueryListForIndex 】-【 STARTED 】");

		List<EduLec> array = eduLecDao.queryListForIndex();

		Iterator<EduLec> it = array.iterator();
		while (it.hasNext()) {
			EduLec entity = it.next();
			logger.debug(" 长度为 "+entity.getDetail().length());
			if (entity.getDetail().length() > 30) {
				entity.setDetail(StrUtil.cutStr(entity.getDetail(), 60) + "...");
			}
		}

		logger.debug(" 【 Serv 】-【 EduLecServ 】-【 QueryListForIndex 】-【 COMPLETED 】");
		return array;

	}

}
